package com.example.gitpart03;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.fragment.app.Fragment;

public class ShouYeFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_shouye, container, false);

        // 绑定"线上点餐"按钮
        Button btnOnlineOrder = view.findViewById(R.id.btn_online_order);
        btnOnlineOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到shouye_second_page
                if (getActivity() != null) {
                    // 创建SecondPageFragment实例
                    SecondPageFragment secondPageFragment = new SecondPageFragment();
                    // 开启Fragment事务
                    getActivity().getSupportFragmentManager().beginTransaction()
                            .replace(R.id.fragment_container, secondPageFragment)
                            .addToBackStack(null) // 可选：添加到返回栈，允许按返回键回到首页
                            .commit();
                }
            }
        });

        return view;
    }
}